package hot100;

import DTO.TreeNode;

public class flatten2 {
    public void flatten(TreeNode root) {
        while (root != null) {
            if (root.left == null) {
                root = root.right;
            } else {
                TreeNode right = root.left;
                while (right.right != null) {
                    right = right.right;
                }
                right.right = root.right;

                root.right = root.left;
                root.left = null;

                root = root.right;
            }
        }

    }
}
